package com.ys.otms.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ys.otms.dto.ParamDto;
import com.ys.otms.services.IConsumeServices;
import com.ys.otms.utils.PageUtil;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/10/12.
 */
@Controller
@RequestMapping("/consume")
public class ConsumeController {
    private static Logger logger = LoggerFactory.getLogger(ConsumeController.class);
    @Autowired
    private IConsumeServices iConsumeServices;
    /**
     * 查询消费记录
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping("/selectConsumeQuery")
    @ResponseBody
    public String selectConsumeQuery(@RequestParam(value = "page")String page, @RequestParam(value = "limit")String limit, HttpServletRequest request) throws Exception{
        logger.info("ConsumeController selectConsumeQuery start");
        Map<String,Object> map = new HashMap<>();
        try {
            ParamDto paramDto = new ParamDto();
            PageUtil.setPage(Integer.parseInt(page),Integer.parseInt(limit),paramDto);
            map = iConsumeServices.selectConsumeQuery(request,paramDto);
            map.put("code","");
            map.put("msg","");
        } catch (Exception e) {
            logger.error("BillsController selectBillsQuery Exception",e);
            map.put("msg","查询失败");
            map.put("code","");
        }
        return new ObjectMapper().writeValueAsString(map);
    }
}
